local skel = fk.CreateSkill {
  name = "emo__yizuo",
}

Fk:loadTranslationTable{
  ["emo__yizuo"] = "懿佐",
  [":emo__yizuo"] = "每当一名角色判定生效前，你可以观看其手牌并选择一张代替之，若为♠牌，你对其造成1点雷电伤害。",

  ["#emo__yizuo-self"] = "懿佐：你可以选择一张手牌代替“%arg”判定牌，若为♠牌，你受到造成1点雷电伤害",
  ["#emo__yizuo-invoke"] = "懿佐：你可以观看 %dest 的手牌并选择一张代替其“%arg”判定牌",
  ["#emo__yizuo-card"] = "懿佐：选择其一张手牌替换判定牌，若为♠牌对其造成伤害",

  ["$emo__yizuo1"] = "我的本命武将，司马懿",
}

skel:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target and not target:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local cost_data = {tos = {target}}
    if player == target then
      local cards = player.room:askToCards(player, {
        min_num = 1, max_num = 1, include_equip = false, skill_name = skel.name, prompt = "#emo__yizuo-self:::" .. data.reason
      })
      if #cards == 0 then return false end
      cost_data.cards = cards
    end
    if target ~= player and not player.room:askToSkillInvoke(player, {
      skill_name = skel.name, prompt = "#emo__yizuo-invoke::"..target.id..":"..data.reason}
    ) then
      return false
    end
    event:setCostData(self, cost_data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    if not cards then
      cards = {room:askToChooseCard(player, {
        target = target, skill_name = skel.name, "#emo__yizuo-card",
        flag = { card_data = { { "$Hand", target.player_cards[Player.Hand] } } }
      })}
    end
    local card = Fk:getCardById(cards[1])
    room:changeJudge{data = data, player = player, skillName = skel.name, card = card}
    if not target.dead and card.suit == Card.Spade then
      room:doIndicate(player, {target})
      room:damage { from = player, to = target, damage = 1, skillName = skel.name, damageType = fk.ThunderDamage }
    end
  end,
})

return skel
